﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;



namespace Urgencias.Vista
{
    public partial class Principal : Form
    {
        private static Principal instance;

        public void refrescarBarra()
        {
            menu.Enabled = true;
        }

        public void limpiar()
        {
            foreach (Control c in this.Controls)
            {
                if (c.Name != "menu")
                    //Instance.Controls.RemoveAt(Instance.Controls.Count - 1);

                    Instance.Controls.Remove(c);
            }

        }

        private Principal()
        {

            InitializeComponent();

            LoginUserControl loginUserControl = new LoginUserControl();
            loginUserControl.Location = new System.Drawing.Point(0, 27);
            loginUserControl.Name = "loginUserControl";
            loginUserControl.Size = new System.Drawing.Size(580, 330);
            loginUserControl.TabIndex = 1;
            this.Controls.Add(loginUserControl);
            menu.Enabled = false;
        }

        public static Principal Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new Principal();
                }
                return instance;
            }
        }

        private void nuevoPacienteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                var control = this.Controls.Find("nuevoPaciente", true).FirstOrDefault() as IngresarMedicoUC;

                if (control == null)
                {
                    IngresarPacienteUC pac = new IngresarPacienteUC();

                    limpiar();
                    pac.Name = "nuevoPaciente";
                    pac.Location = new System.Drawing.Point(0, 27);
                    pac.Size = new System.Drawing.Size(580, 330);
                    pac.TabIndex = 1;
                    this.Controls.Add(pac);
                }

            }
            catch (Exception)
            {

                throw;
            }
        }

        private void cerrarSesionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                var control = this.Controls.Find("loginUserControl", true).FirstOrDefault() as LoginUserControl;

                if (control == null)
                {
                    limpiar();
                    LoginUserControl loginUserControl = new LoginUserControl();
                    loginUserControl.Location = new System.Drawing.Point(0, 27);
                    loginUserControl.Name = "loginUserControl";
                    loginUserControl.Size = new System.Drawing.Size(580, 330);
                    loginUserControl.TabIndex = 1;
                    this.Controls.Add(loginUserControl);
                    menu.Enabled = false;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }

        private void nuevoMedicoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                var control = this.Controls.Find("nuevoMedico", true).FirstOrDefault() as IngresarMedicoUC;

                if (control == null)
                {
                    limpiar();
                    IngresarMedicoUC nuevoMedico = new IngresarMedicoUC();
                    nuevoMedico.Name = "nuevoMedico";
                    nuevoMedico.Location = new System.Drawing.Point(0, 27);
                    nuevoMedico.Size = new System.Drawing.Size(580, 330);
                    nuevoMedico.TabIndex = 1;
                    this.Controls.Add(nuevoMedico);
                }
            }
            catch (Exception)
            {
                //e.Message;                
                throw;
            }

        }

       

        private void listadoPacientesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                var control = this.Controls.Find("ListadoPacientes", true).FirstOrDefault() as ListadoPacientesUC;

                if (control == null)
                {
                    //this.Controls.RemoveAt(this.Controls.Count - 1);
                    limpiar();
                    ListadoPacientesUC listadoPacientes = new ListadoPacientesUC();
                    listadoPacientes.Name = "ListadoPacientes";
                    listadoPacientes.Location = new System.Drawing.Point(0, 27);
                    listadoPacientes.Size = new System.Drawing.Size(580, 340);
                    listadoPacientes.TabIndex = 1;
                    this.Controls.Add(listadoPacientes);
                }

            }
            catch (Exception)
            {

                throw;
            }

        }

        private void modificarPacienteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                var control = this.Controls.Find("modificarPaciente", true).FirstOrDefault() as ModificarPacienteUC;

                if (control == null)
                {
                    limpiar();
                    ModificarPacienteUC modificarPaciente = new ModificarPacienteUC();
                    modificarPaciente.Name = "modificarPaciente";
                    modificarPaciente.Location = new System.Drawing.Point(0, 27);
                    modificarPaciente.Size = new System.Drawing.Size(580, 340);
                    modificarPaciente.TabIndex = 1;
                    this.Controls.Add(modificarPaciente);
                }

            }
            catch (Exception)
            {

                throw;
            }
        }

        private void listadoMedicosToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                var control = this.Controls.Find("ListadoMedicos", true).FirstOrDefault() as ListadoMedicoUC;

                if (control == null)
                {
                    //this.Controls.RemoveAt(this.Controls.Count - 1);
                    limpiar();
                    ListadoMedicoUC listadoMedicos = new ListadoMedicoUC();
                    listadoMedicos.Name = "ListadoMedicos";
                    listadoMedicos.Location = new System.Drawing.Point(0, 27);
                    listadoMedicos.Size = new System.Drawing.Size(580, 340);
                    listadoMedicos.TabIndex = 1;
                    this.Controls.Add(listadoMedicos);
                }

            }
            catch (Exception)
            {

                throw;
            }
        }

        private void nuevaConsultaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                var control = this.Controls.Find("nuevaConsulta", true).FirstOrDefault() as IngresarUrgenciaUC;

                if (control == null)
                {
                    //this.Controls.RemoveAt(this.Controls.Count - 1);
                    limpiar();
                    IngresarUrgenciaUC nuevaConsulta = new IngresarUrgenciaUC();
                    nuevaConsulta.Name = "nuevaConsulta";
                    nuevaConsulta.Location = new System.Drawing.Point(0, 27);
                    nuevaConsulta.Size = new System.Drawing.Size(580, 340);
                    nuevaConsulta.TabIndex = 1;
                    this.Controls.Add(nuevaConsulta);
                }

            }
            catch (Exception)
            {

                throw;
            }
        }

        private void listadoUrgenciasToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                var control = this.Controls.Find("listadoUrgencia", true).FirstOrDefault() as ListadoUrgenciasUC;

                if (control == null)
                {
                    //this.Controls.RemoveAt(this.Controls.Count - 1);
                    limpiar();
                    ListadoUrgenciasUC listadoUrgencia = new ListadoUrgenciasUC();
                    listadoUrgencia.Name = "listadoUrgencia";
                    listadoUrgencia.Location = new System.Drawing.Point(0, 27);
                    listadoUrgencia.Size = new System.Drawing.Size(580, 340);
                    listadoUrgencia.TabIndex = 1;
                    this.Controls.Add(listadoUrgencia);
                }

            }
            catch (Exception)
            {

                throw;
            }
        }

        private void modificarMedicoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                var control = this.Controls.Find("modificarMedico", true).FirstOrDefault() as ModificarMedicoUC;

                if (control == null)
                {
                    //this.Controls.RemoveAt(this.Controls.Count - 1);
                    limpiar();
                    ModificarMedicoUC modificarMedico = new ModificarMedicoUC();
                    modificarMedico.Name = "modificarMedico";
                    modificarMedico.Location = new System.Drawing.Point(0, 27);
                    modificarMedico.Size = new System.Drawing.Size(580, 340);
                    modificarMedico.TabIndex = 1;
                    this.Controls.Add(modificarMedico);
                }

            }
            catch (Exception)
            {

                throw;
            }

        }

        private void modificarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                var control = this.Controls.Find("modificarUrgencia", true).FirstOrDefault() as ModificarUrgenciaUC;

                if (control == null)
                {
                    //this.Controls.RemoveAt(this.Controls.Count - 1);
                    limpiar();
                    ModificarUrgenciaUC modificarUrgencia = new ModificarUrgenciaUC();
                    modificarUrgencia.Name = "modificarUrgencia";
                    modificarUrgencia.Location = new System.Drawing.Point(0, 27);
                    modificarUrgencia.Size = new System.Drawing.Size(580, 340);
                    modificarUrgencia.TabIndex = 1;
                    this.Controls.Add(modificarUrgencia);
                }

            }
            catch (Exception)
            {

                throw;
            }
        }


        private void nuevoEnfermeroToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                var control = this.Controls.Find("nuevoEnfermero", true).FirstOrDefault() as IngresarEnfermeroUC;

                if (control == null)
                {
                    limpiar();
                    IngresarEnfermeroUC nuevoEnfermero = new IngresarEnfermeroUC();
                    nuevoEnfermero.Name = "nuevoEnfermero";
                    nuevoEnfermero.Location = new System.Drawing.Point(0, 27);
                    nuevoEnfermero.Size = new System.Drawing.Size(580, 330);
                    nuevoEnfermero.TabIndex = 1;
                    this.Controls.Add(nuevoEnfermero);
                }
            }
            catch (Exception)
            {
                //e.Message;                
                throw;
            }

        }

        private void modificarEnfermeroToolStripMenuItem_Click(object sender, EventArgs e)//nuevo//
        {
            try
            {
                var control = this.Controls.Find("modificarEnfermero", true).FirstOrDefault() as ModificarEnfermeroUC;

                if (control == null)
                {
                    limpiar();
                    ModificarEnfermeroUC modificarEnfermero = new ModificarEnfermeroUC();
                    modificarEnfermero.Name = "modificarEnfermero";
                    modificarEnfermero.Location = new System.Drawing.Point(0, 27);
                    modificarEnfermero.Size = new System.Drawing.Size(580, 340);
                    modificarEnfermero.TabIndex = 1;
                    this.Controls.Add(modificarEnfermero);
                }

            }
            catch (Exception)
            {

                throw;
            }
        }

        private void eliminarEnfermeroToolStripMenuItem_Click(object sender, EventArgs e)//falta//
        {
            
        }

        private void listaEnfermeroToolStripMenuItem_Click(object sender, EventArgs e)//nuevo//
        {
            {
                try
                {
                    var control = this.Controls.Find("ListadoEnfermero", true).FirstOrDefault() as ListadoEnfermerosUC;

                    if (control == null)
                    {
                        //this.Controls.RemoveAt(this.Controls.Count - 1);
                        limpiar();
                        ListadoEnfermerosUC listadoEnfermero = new ListadoEnfermerosUC();
                        listadoEnfermero.Name = "ListadoEnfermero";
                        listadoEnfermero.Location = new System.Drawing.Point(0, 27);
                        listadoEnfermero.Size = new System.Drawing.Size(580, 340);
                        listadoEnfermero.TabIndex = 1;
                        this.Controls.Add(listadoEnfermero);
                    }

                }
                catch (Exception)
                {

                    throw;
                }
            }
        }


        private void ingresarInsumosToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                var control = this.Controls.Find("ingresarInsumo", true).FirstOrDefault() as IngresarInsumosUC;

                if (control == null)
                {
                    limpiar();
                    IngresarInsumosUC ingresarInsumo = new IngresarInsumosUC();
                    ingresarInsumo.Name = "ingresarInsumo";
                    ingresarInsumo.Location = new System.Drawing.Point(0, 27);
                    ingresarInsumo.Size = new System.Drawing.Size(580, 330);
                    ingresarInsumo.TabIndex = 1;
                    this.Controls.Add(ingresarInsumo);
                }
            }
            catch (Exception)
            {
                //e.Message;                
                throw;
            }
        }

        private void modificarInsumosToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                var control = this.Controls.Find("modificarInsumo", true).FirstOrDefault() as ModificarInsumosUC;

                if (control == null)
                {
                    limpiar();
                    ModificarInsumosUC modificarInsumo = new ModificarInsumosUC();
                    modificarInsumo.Name = "modificarInsumo";
                    modificarInsumo.Location = new System.Drawing.Point(0, 27);
                    modificarInsumo.Size = new System.Drawing.Size(580, 330);
                    modificarInsumo.TabIndex = 1;
                    this.Controls.Add(modificarInsumo);
                }
            }
            catch (Exception)
            {
                //e.Message;                
                throw;
            }
        }

        private void nuevaConsultaToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            try
            {
                var control = this.Controls.Find("nuevaConsulta", true).FirstOrDefault() as IngresarConsultaUC;//no se donde crear ingresaenfermero

                if (control == null)
                {
                    limpiar();
                    IngresarConsultaUC nuevaConsulta = new IngresarConsultaUC();
                    nuevaConsulta.Name = "nuevaConsulta";
                    nuevaConsulta.Location = new System.Drawing.Point(0, 27);
                    nuevaConsulta.Size = new System.Drawing.Size(580, 330);
                    nuevaConsulta.TabIndex = 1;
                    this.Controls.Add(nuevaConsulta);
                }
            }
            catch (Exception)
            {
                //e.Message;                
                throw;
            }
        }

        private void eliminarConsultaToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void modificarConsultaToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void eliminarConsultaToolStripMenuItem1_Click(object sender, EventArgs e)
        {

        }

        private void listadoConsultasToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void eliminarPacienteToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void nuevoPagoToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void modificarPagoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
        }

        private void listadoPagosToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                var control = this.Controls.Find("ListadoEnfermero", true).FirstOrDefault() as ListadoPagoUC;

                if (control == null)
                {
                    //this.Controls.RemoveAt(this.Controls.Count - 1);
                    limpiar();
                    ListadoPagoUC listadoPago = new ListadoPagoUC();
                    listadoPago.Name = "ListadoEnfermero";
                    listadoPago.Location = new System.Drawing.Point(0, 27);
                    listadoPago.Size = new System.Drawing.Size(580, 340);
                    listadoPago.TabIndex = 1;
                    this.Controls.Add(listadoPago);
                }

            }
            catch (Exception)
            {

                throw;
            }
        }

        private void eliminarInsumoToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void listadoInsumosToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                var control = this.Controls.Find("listadoInsumos", true).FirstOrDefault() as ListadoInsumosUC;

                if (control == null)
                {
                    //limpiar();
                    ListadoInsumosUC listadoInsumos = new ListadoInsumosUC();
                    listadoInsumos.Name = "listadoInsumos";
                    listadoInsumos.Location = new System.Drawing.Point(0, 27);
                    listadoInsumos.Size = new System.Drawing.Size(580, 330);
                    listadoInsumos.TabIndex = 1;
                    this.Controls.Add(listadoInsumos);
                }
            }
            catch (Exception)
            {
                //MessageBox.Show(e.ToString());                
                throw;
            }

        }

        private void ingresarBoxToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                var control = this.Controls.Find("listadoInsumos", true).FirstOrDefault() as ListadoInsumosUC;

                if (control == null)
                {
                    //limpiar();
                    IngresarBoxUC IngresarBox = new IngresarBoxUC();
                    IngresarBox.Name = "listadoInsumos";
                    IngresarBox.Location = new System.Drawing.Point(0, 27);
                    IngresarBox.Size = new System.Drawing.Size(580, 330);
                    IngresarBox.TabIndex = 1;
                    this.Controls.Add(IngresarBox);
                }
            }
            catch (Exception)
            {
                MessageBox.Show(e.ToString());
                throw;
            }
        }

        private void modificarBoxToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void eliminarBoxToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void listadoBoxesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                var control = this.Controls.Find("ListadoEnfermero", true).FirstOrDefault() as ListadoBoxesUC;

                if (control == null)
                {
                    //this.Controls.RemoveAt(this.Controls.Count - 1);
                    limpiar();
                    ListadoBoxesUC listadoBoxes = new ListadoBoxesUC();
                    listadoBoxes.Name = "ListadoEnfermero";
                    listadoBoxes.Location = new System.Drawing.Point(0, 27);
                    listadoBoxes.Size = new System.Drawing.Size(580, 340);
                    listadoBoxes.TabIndex = 1;
                    this.Controls.Add(listadoBoxes);
                }

            }
            catch (Exception)
            {

                throw;
            }
        }

        private void eliminarMedicoToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

    }
}